package com.liao.note.controller;

import com.liao.note.domain.Category;
import com.liao.note.enums.ResultCode;
import com.liao.note.service.CategoryService;
import com.liao.note.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @RequestMapping(value = "/list/{userId}", method = RequestMethod.GET)
    public ResultVO<Object> queryList(@PathVariable("userId") Integer userId) {
        return new ResultVO<>(categoryService.queryByUserId(userId));
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResultVO<Object> add(@RequestBody Category category) {
        int insert = categoryService.insert(category);
        return new ResultVO<>(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultVO<Object> update(@RequestBody Category category) {
        int update = categoryService.update(category);
        return new ResultVO<>(ResultCode.SUCCESS);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    public ResultVO<Object> delete(@PathVariable("id") Integer id) {
        int i = categoryService.deleteById(id);
        return new ResultVO<>(ResultCode.SUCCESS);
    }

}
